package vn.allmobile.ambnews.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferenceManager {
	
	private static Context _context = GlobalApplication._();

	public static void init()
	{
		SharedPreferences.Editor localEditor = _context.getSharedPreferences( Contants.PREFERENCE_NAME, 0).edit();	   
	    
	    localEditor.putString("update_interval", "15");
	    localEditor.putString("description_font", "8pt");	
	    localEditor.putString("max_items_per_channel", "20");	    	   
	    localEditor.putBoolean("auto_update", true);
	    localEditor.putBoolean("stop_updating_in_sleep_time", true);	    
	    localEditor.putBoolean("notification", true);	    
	    localEditor.putBoolean("notification_sound", true);
	    localEditor.putBoolean("notification_vibrate", true);
	    localEditor.putBoolean("notification_light", true);
	    localEditor.putBoolean("wifi_only", true);
	    
	    localEditor.commit();
	}
	
	public static void setPaperVersion(int paramInt)
	{		  
		SharedPreferences.Editor localEditor = _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).edit();
	    localEditor.putInt("paper_vers", paramInt);
	    localEditor.commit();
	 
	}
	
	public static int getPaperVersion()
	{		  
		return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getInt("paper_vers", 0);		 
	}
	
	public static long getLastSyncTime()
	{		  
		return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getLong("last_sync", 0L);		 
	}
	
	public static String getfontSize()
	{
		return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getString("description_font","8pt");
	}
	
	public static int getArticleLimit()
	{		  
		return Integer.parseInt(_context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getString("max_items_per_channel", "20"));		 
	}
	
	public static int getIntervalUpdateTime()
	{
		return Integer.parseInt(_context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getString("update_interval", "15"));
		//return 1;
	}
	
	public static boolean isFirstTime()
	{
		return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("first_time", true);
	}
	
	
	public static boolean isUpdateEnable()
	{
		return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("auto_update", true);
		//return true;
	}
	
	public static boolean isStopInSleep()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("stop_updating_in_sleep_time", true);
	  }
	
	
	public static boolean isNightMode()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("night_mode", false);
	  }
	
	
	public static boolean isWifiOnly()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("wifi_only", true);
	  }
	
	public static void setLastSyncTime(long paramLong)
	  {
	    SharedPreferences.Editor localEditor = _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).edit();
	    localEditor.putLong("last_sync", paramLong);
	    localEditor.commit();
	  }
	
	public static void setisFirstTime()
	  {
	    SharedPreferences.Editor localEditor = _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).edit();
	    localEditor.putBoolean("first_time", false);
	    localEditor.commit();
	  }
	
	 public static boolean isNotification()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("notification", false);
	  }
	 public static boolean notificationSound()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("notification_sound", false);
	  }
	 public static boolean notificationVibrate()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("notification_vibrate", false);
	  }

	  public static boolean notificationLight()
	  {
	    return _context.getSharedPreferences(Contants.PREFERENCE_NAME, 0).getBoolean("notification_light", false);
	  }
}
